package top.meijhm.communitymanagement.user.model;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;

@Entity
@Table(name = "user", indexes = {
        @Index(name = "username", columnList = "username")
})
@ApiModel(value = "User", description = "用户api")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    @ApiModelProperty(value = "用户id", hidden = true)
    private Long id;
    @Column(name = "username", length = 32)
    @ApiModelProperty(value = "用户名，长度1~32", required = true, example = "user")
    @Size(min = 1, max = 32, message = "用户名长度错误")
    @NotBlank(message = "不能为空")
    private String username;
    @Column(name = "password", length = 60)
    @ApiModelProperty(value = "密码，长度1~60", required = true, example = "12345")
    @Size(min = 1, max = 60, message = "用户密码长度错误")
    @NotBlank(message = "不能为空")
    private String password;
    @Column(name = "description", length = 100)
    @ApiModelProperty(value = "描述，长度0~100", example = "这是一段描述")
    @Size(max = 100, message = "描述长度太长，错误")
    private String description;
    @Column(name = "enabled")
    @ApiModelProperty(value = "是否启用，true or false", example = "true")
    @NotNull
    private Boolean enabled;
    @Column(name = "deleted")
    @ApiModelProperty(value = "是否被删除，true or false", hidden = true)
    @NotNull
    private Boolean deleted;
    @ApiModelProperty(value = "创建时间", hidden = true)
    @Column(name = "created_time")
    @Temporal(TemporalType.TIMESTAMP)
    @NotNull
    private Date createdTime;
    @ApiModelProperty(value = "更新时间", hidden = true)
    @Column(name = "updated_time")
    @Temporal(TemporalType.TIMESTAMP)
    @NotNull
    private Date updatedTime;
    @Column(name = "user_role")
    @ApiModelProperty(value = "用户角色", required = true, example = "ROLE_USER", allowableValues = "ROLE_ADMIN，ROLE_USER")
    @Enumerated(EnumType.STRING)
    @NotNull
    private UserRole userRole;
}